/*
 * 文 件 名:  ${tableName}ServiceImpl.java
 * 版   权: Copyright www.${company}.com Corporation ${dateYear} 版权所有
 * 描     述:  <描述>
 * 修 改 人:  mingbao
 * 修改时间:  ${dateTime}
 * 跟踪单号: <跟踪单号>
 * 修改单号: <修改单号>
 * 修改内容: <修改内容>
 */
package com.${company}.${projectName}.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.${company}.${projectName}.dao.${tableName}Dao;
import com.${company}.${projectName}.model.${tableName}Model;
import com.${company}.${projectName}.service.${tableName}Service;
import com.alibaba.fastjson.JSON;
import com.teshehui.framework.util.page.Page;
import com.teshehui.supplier.model.SupplierBrandModel;

/**
 * <一句话功能简述>
 * <功能详细描述>
 * 
 * @author  mingbao
 * @version  [版本号, ${dateTime}]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Service("${tableNameMin}Service")
public class ${tableName}ServiceImpl implements ${tableName}Service
{
    private static final Log logger = LogFactory.getLog(${tableName}ServiceImpl.class);

    @Resource
    private ${tableName}Dao  ${tableNameMin}Dao;

    public void add${tableName}(${tableName}Model ${tableNameMin}Model)throws Exception
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--add${tableName} Params-->" + JSON.toJSONString(${tableNameMin}Model));
        }
        ${tableNameMin}Dao.insert(${tableNameMin}Model);
    }
    
    /**
     * 批量插入只支持mysql
     */
    @Override
	public void add${tableName}List(
			List<${tableName}Model> ${tableNameMin}ModelList) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("--add${tableName}List Params-->"
					+ JSON.toJSONString(${tableNameMin}ModelList));
		}
		if (${tableNameMin}ModelList != null && ${tableNameMin}ModelList.size() > 0) {
			${tableNameMin}Dao.insertList(${tableNameMin}ModelList);
		}
	}

    public void update${tableName}ById(${tableName}Model ${tableNameMin}Model)throws Exception
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--add${tableName}  Params-->" + JSON.toJSONString(${tableNameMin}Model));
        }
        ${tableNameMin}Dao.update(${tableNameMin}Model);
    }

    public ${tableName}Model get${tableName}ById(${tableName}Model ${tableNameMin}Model)throws Exception
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName}ById Params-->" + JSON.toJSONString(${tableNameMin}Model));
        }  
        ${tableName}Model result = ${tableNameMin}Dao.queryOne(${tableNameMin}Model);
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName}ById result-->" + JSON.toJSONString(result));
        }
        return result;
    }

    public long get${tableName}Count(${tableName}Model ${tableNameMin}Model)throws Exception
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName}Count Params-->" + JSON.toJSONString(${tableNameMin}Model));
        }
        long result = ${tableNameMin}Dao.countListPage(${tableNameMin}Model);
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName}Count result-->" + JSON.toJSONString(result));
        }
        return result;
    }

    public List<${tableName}Model> get${tableName}(${tableName}Model ${tableNameMin}Model, Page page)throws Exception
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName} Params-->" + JSON.toJSONString(${tableNameMin}Model));
        }
        long count = ${tableNameMin}Dao.countListPage(${tableNameMin}Model);
        List<${tableName}Model> result=null;
        if (count > 0) {
        	 page.setTotalCount(count);
        result= ${tableNameMin}Dao.queryListPage(${tableNameMin}Model, page.getPageNum(), page.getNumPerPage());
        }
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName} result-->" + JSON.toJSONString(result));
        }
        return result;
    }

    public void deleteById(${tableName}Model ${tableNameMin}Model)throws Exception
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--deleteById Params-->" + JSON.toJSONString(${tableNameMin}Model));
        }
        ${tableNameMin}Dao.delete(${tableNameMin}Model);
    }
    
    @Override
	public void deleteByIds(List<Long> ids) throws Exception {
		if (logger.isDebugEnabled())
        {
            logger.debug("--deleteByIds Params-->" + JSON.toJSONString(ids));
        }
		${tableNameMin}Dao.deleteByIds(ids); 
		
	}

}
